home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************/
- /* */
- /* Source - 4th Class.c */
- /* Author - Alexander S. Colwell, Copyright © 1990 */
- /* */
- /* Purpose - This 4th Dimension's External Area class. */
- /* */
- /************************************************************************/
-
- #include "4th Class.h" /* 4th Ext Area Class defs */
-
- C4th *New(void); /* "New" function proto-type */
-
- pascal void main(eaEvent, eaRect, eaName, eaObject)
- EventRecord *eaEvent; /* External Area event pointer */
- Rect *eaRect; /* External Rect area pointer */
- char *eaName; /* External Area name pointer */
- C4th **eaObject; /* External Area object */
- {
- WindowPtr curWPtr; /* Working current window pointer */
- C4th *fake; /* Working fake object for "Layouts"*/
-
- RememberA0(); /* Save register A0 for A4 */
- SetUpA4(); /* Setup register A4 */
-
- if (eaEvent->what == drawReq) {/* Check if "Layout" draw */
- eaEvent->message = 102; /* Let's draw other "0101010101" */
-
- fake = New(); /* Create fake object */
-
- GetPort(&curWPtr); /* Get current window pointer */
- fake->layout = TRUE; /* Set layout update state */
- fake->wPtr = curWPtr; /* Save window pointer */
- fake->name = eaName; /* Save external area name */
- fake->event = eaEvent; /* Save event record ptr */
- fake->drawArea = *eaRect;/* Setup drawing area */
- fake->prevArea = *eaRect;/* Setup previous area */
- fake->width = eaRect->right - eaRect->left;/* Set width */
- fake->height = eaRect->bottom - eaRect->top;/* Set height */
- fake->tmpRgn = NULL; /* Invalidate region */
-
- eaEvent->what = initEvt;/* Fake init event */
- fake->Message(); /* Handle message */
-
- eaEvent->what = updateEvt;/* Fake update event */
- fake->Message(); /* Handle message */
-
- eaEvent->what = deInitEvt;/* Fake deinit event */
- fake->Message(); /* Handle message */
-
- SetPort(curWPtr); /* Restore previous window port */
- }
-
- else { /* Do real-thing */
-
- if (eaEvent->what == initEvt) {/* Check if its initalization*/
- *eaObject = New(); /* Create new object */
- (*eaObject)->layout = FALSE;/* Set not layout state */
- (*eaObject)->tmpRgn = NULL;/* Invalidate region */
- (*eaObject)->wPtr = NULL;/* Invalidate window pointer */
- (*eaObject)->prevArea = *eaRect;/* Set previous rect area*/
- }
-
- if (*eaObject) { /* Check if got object */
- GetPort(&curWPtr); /* Get current window pointer */
- (*eaObject)->wPtr = curWPtr;/* Save window pointer */
- (*eaObject)->name = eaName;/* Save external area name */
- (*eaObject)->event = eaEvent;/* Save event record ptr */
- (*eaObject)->drawArea = *eaRect;/* Setup drawing area */
- (*eaObject)->width = eaRect->right - eaRect->left;
- (*eaObject)->height = eaRect->bottom - eaRect->top;
- (*eaObject)->Message();/* Handle message */
- SetPort(curWPtr); /* Restore previous window port */
- }
- }
-
- RestoreA4(); /* Restore register A4 */
- }
-
- void C4th::Message(void) /* Dispatch message */
- {
- register short what; /* Working event type */
- Rect wRect; /* Working rect area */
-
- SaveStates(); /* Save states for drawing */
-
- switch(what = event->what) {/* Process event message */
- case nullEvent: /* Null event handler */
- Idle(); break;
-
- case initEvt: /* Init event */
- IExtArea(FALSE); break;
-
- case deInitEvt: /* Close event */
- Close(); break;
-
- case cursorEvt: /* Cursor event */
- Cursor(event->where); break;
-
- case selectReq: /* Selection request event */
- if (keyBoardEvents) /* Check if want keyboard selection */
- event->message = 101;/* Set keyboard request */
- break;
-
- case activNote: /* Activate selection event */
- Select(); break;
-
- case deActivNote: /* Deactivate selection event */
- Deselect(); break;
-
- case scrollEvt: /* Scroll event */
- Scroll(); break;
-
- case undoEvt: /* Edit's "Undo" event */
- DoUndo(); break;
-
- case cutEvt: /* Edit's "Cut" event */
- DoCut(); break;
-
- case copyEvt: /* Edit's "Copy" event */
- DoCopy(); break;
-
- case pasteEvt: /* Edit's "Paste" event */
- DoPaste(); break;
-
- case clearEvt: /* Edit's "Clear" event */
- DoClear(); break;
-
- case selectAllEvt: /* Edit's "Select All" event */
- DoSelectAll(); break;
-
- case afterActivEvt: /* After "ActivNote" event */
- break;
-
- case afterDeactivEvt: /* After "DeactivNote" event */
- break;
-
- case activeIdleEvt: /* Selection idle event */
- break;
-
- case updateEvt: /* Update external area */
- wRect = drawArea; /* Set drawing area to erase */
- EraseRect(&wRect); /* Clear it now for updating */
- Draw(); /* Do "Draw" method */
- break;
-
- case mouseDown: /* Mouse down in external area */
- DoClick(event->where,event->modifiers,event->when);
- break;
-
- case keyDown: /* Key down event */
- case autoKey: /* Auto-key down event */
- DoKeyDown(event->message & charCodeMask,
- (event->message & keyCodeMask) >> 8); break;
-
- default: /* Don't know this event */
- break;
- }
-
- if (what != deInitEvt) /* Check if not closing */
- RestoreStates(); /* Restore drawing states */
- }
-
- void C4th::IExtArea(short getKeyBoard)/* Init external area method */
- {
- short rom; /* Working ROM id */
- short machine; /* Working Mac id */
- register short canDoIt; /* Working can do it indicator */
- SysEnvRec wSysEnv; /* Working system configuration */
-
- dirty = FALSE; /* Mark ext area not dirty */
- active = FALSE; /* Mark ext area not active */
- keyBoardEvents = getKeyBoard;/* Set get keyboard events flag */
- tmpRgn = NewRgn(); /* Temporary region */
-
- originalMac = FALSE; /* Set not using 128K/512K Macs */
- hasGraphicDevices = FALSE; /* Set has no graphic devices */
- sysEnv.environsVersion = 0; /* Set bogus system configuration */
- sysEnv.machineType = 0;
- sysEnv.systemVersion = 0;
- sysEnv.processor = 0;
- sysEnv.hasFPU = FALSE;
- sysEnv.hasColorQD = FALSE;
- sysEnv.keyBoardType = 0;
- sysEnv.atDrvrVersNum = 0;
- sysEnv.sysVRefNum = 0;
-
- Environs(&rom,&machine); /* Get Mac's evniroment */
- if (machine == macXLMachine)/* Check if Lisa clone */
- canDoIt = FALSE; /* It's a Lisa computer! */
- else if (rom >= macIIROM) /* It's Mac II */
- canDoIt = TRUE; /* It's Mac II computer */
- else if (rom >= macSEROM) /* It's Mac SE */
- canDoIt = TRUE; /* It's Mac SE computer */
- else if (rom >= macPlusROM) {/* it's 128K rom */
- /* Check if Mac 512KE computer */
- if (MemTop > (char *)(1024L * 512L))
- canDoIt = TRUE; /* It's Mac 512K Enhanced */
- else
- canDoIt = TRUE; /* Its Mac Plus computer */
- }
- else if (rom >= macROM) { /* It's 64K rom, it's old one */
- canDoIt = FALSE; /* It's original Mac! */
- originalMac = TRUE;
- }
- if (canDoIt) { /* OK, we can do it! */
-
- /* Check if SysEnvirons valid */
- if ((long)NGetTrapAddress(SysEnvironsTrap,OSTrap) !=
- (long)NGetTrapAddress(UnknownTrap,ToolTrap)) {
- SysEnvirons(1,&wSysEnv);/* Get system enviroment */
- sysEnv = wSysEnv; /* Save system configuration */
- }
-
- /* Check if "Graphics Device" valid */
- if ((long)NGetTrapAddress(GetDeviceListTrap,ToolTrap) !=
- (long)NGetTrapAddress(UnknownTrap,ToolTrap))
- hasGraphicDevices = TRUE;/* Mark it available */
- }
- }
-
- void C4th::Close(void) /* Close external area method */
- {
- RestoreStates(); /* Restore drawing states */
- if (tmpRgn) /* Check if have temp region handle */
- DisposeRgn(tmpRgn); /* Release temp region handle */
- tmpRgn = NULL; /* Invalidate temp region handle */
- delete(this); /* Release this object */
- }
-
- void C4th::Idle(void) /* Idle method */
- {
- if (dirty) { /* Check if it's dirty */
- Draw(); /* Re-draw everything!!! */
- dirty = FALSE; /* Reset dirty indicator */
- }
- }
-
- void C4th::Cursor(Point pt) /* Cursor over external area method */
- {
- CursHandle crossHdl; /* Working cross cursor handle */
-
- if (crossHdl = GetCursor(crossCursor))/* Check if got cursor */
- SetCursor(*crossHdl); /* Set to cross cursor */
- }
-
- void C4th::Select(void) /* Select external area method */
- {
- active = TRUE; /* Mark external area active */
- }
-
- void C4th::Deselect(void) /* Deselect external area method */
- {
- active = FALSE; /* Mark external area not active */
- }
-
- void C4th::Scroll(void) /* Scroll external area method */
- {
- }
-
- void C4th::Draw(void) /* Draw external area method */
- {
- Rect wRect; /* Working rect area */
-
- wRect = drawArea; /* Set drawing rect area */
-
- PaintRect(&wRect); /* Paint it "black" to show something*/
- }
-
- void C4th::DoClick(Point pt, /* Mouse-click in ext area method */
- short modifiers, long ticks)
- {
- }
-
- void C4th::DoKeyDown(char theChar,/* Key-down method */
- Byte keyCode)
- {
- }
-
- void C4th::DoUndo(void) /* Edit "Undo" method */
- {
- }
-
- void C4th::DoCut(void) /* Edit "Cut" method */
- {
- }
-
- void C4th::DoCopy(void) /* Edit "Copy" method */
- {
- }
-
- void C4th::DoPaste(void) /* Edit "Paste" method */
- {
- }
-
- void C4th::DoClear(void) /* Edit "Clear" method */
- {
- }
-
- void C4th::DoSelectAll(void) /* Edit "Select All" method */
- {
- }
-
- void C4th::SaveStates(void) /* Save for drawing */
- {
- GetPenState(&savePenState); /* Get current pen states */
- PenNormal(); /* Normalize pen characteristics */
- saveFont = wPtr->txFont; /* Save current text font's states */
- saveSize = wPtr->txSize;
- saveStyle = wPtr->txFace;
- saveMode = wPtr->txMode;
- }
-
- void C4th::RestoreStates(void) /* Restore drawing stuff */
- {
- SetPenState(&savePenState);/* Restore pen states */
- TextFont(saveFont); /* Restore text font's characteristics*/
- TextSize(saveSize);
- TextFace(saveStyle);
- TextMode(saveMode);
- prevArea = drawArea; /* Save previous area */
- if (tmpRgn) /* Check if has temporary region */
- EmptyRgn(tmpRgn); /* Free-up some memory */
- }
-
- short C4th::TrackMouse(Point pt,RgnHandle rgn)/* Track mouse within region*/
- {
- register RgnHandle wRgn; /* Working region handle */
- register short hilite = FALSE;/* Working hilite state */
- register short status = FALSE;/* Working status indicator */
-
- if (PtInRgn(pt,rgn)) { /* Check if initially inside region */
- if (wRgn = NewRgn()) { /* Check if got new region */
- CopyRgn(rgn,wRgn); /* Copy mouse's region */
- InsetRgn(wRgn,1,1); /* Shrink it a bit for hiliting */
- while(Button()) { /* Do while mouse is down */
- GetMouse(&pt); /* Get next mouse position */
- if (PtInRgn(pt,rgn))/* Check if mouse inside region */
- status = TRUE;/* Set inside the region */
- else /* Nope, outside region */
- status = FALSE;/* Set outside of the region */
- if (hilite != status) {/* Check if change hilite */
- hilite = status;/* Reset hilite state */
- HiliteMode &= 0x7f;/* Set highliting bit */
- InvertRgn(wRgn);/* Invert it */
- }
- }
- if (hilite) { /* Check if restore hilite state */
- HiliteMode &= 0x7f;/* Set highliting bit */
- InvertRgn(wRgn);/* Invert it */
- }
- DisposeRgn(wRgn); /* Release working region handle */
- }
- }
- return(status); /* Return status indicator */
- }
-
- short C4th::UsingColor(void)
- {
- register short hasColor = TRUE;/* Working color indicator */
- register GDHandle theDevice;/* Working screen device */
- Rect globalRect; /* Working global external rect area*/
- Rect wRect; /* Working window rect area */
-
- if (sysEnv.hasColorQD) { /* Check if using color */
- if (hasGraphicDevices) {/* Check if has graphic devices */
- hasColor = TRUE; /* Assume using color */
- globalRect = drawArea;/* Setup global external rect area*/
- LocalToGlobal(&globalRect.top);/* Convert to global (h,v)*/
- LocalToGlobal(&globalRect.bottom);
- theDevice = GetDeviceList();/* Get main device */
- while(hasColor && theDevice) {/* Search B&W device */
- /* Check if window within view */
- if (SectRect(&globalRect,&(*(*theDevice)->gdPMap)->bounds,
- &wRect))
- if ((*(*theDevice)->gdPMap)->pixelSize <= 2)
- hasColor = FALSE;
- theDevice = GetNextDevice(theDevice);/* Get next one*/
- }
- }
- }
- return(hasColor); /* Return color indicator */
- }
-
- int DummyProc() {} /* Dummy procedure */